package com.ad_hccm.dao.Appendix;

import com.ad_hccm.domain.Appendix.AE;
import com.ad_hccm.domain.PatientUser;
import com.ad_hccm.domain.Week.AdverseReactionRecord;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * TODO 不良事件(AE)报告表
 */
@Mapper
public interface AEDao {
    @Insert("insert into ae(id, week, isAE, name, startDate, finishDate, degree, measure, relativity, result, isExit) value(#{id}, #{week}, #{isAE}, #{name}, #{startDate}, #{finishDate}, #{degree}, #{measure}, #{relativity}, #{result}, #{isExit})")
    public boolean save(AE domain);

    @Update("update ae set isAE = #{isAE}, name = #{name}, startDate = #{startDate}, finishDate = #{finishDate}, degree = #{degree}, measure = #{measure}, relativity = #{relativity}, result = #{result}, isExit=#{isExit} where id = #{id} and week = #{week}")
    public boolean update(AE domain);

    @Select("select * from ae where id = #{id}")
    public List<AE> getById(String id);

    @Select("select * from ae where id = #{id} and week = #{week}")
    public AE getWeek(AE domain);

    @Select("select ae.id id, week, isAE, ae.name name, startDate, finishDate, degree, measure, relativity, result, isExit, patient_user.name idName from ae,patient_user where ae.id = patient_user.id and patient_user.doctorId = #{id}")
    public List<AE> getAll(String id);

    @Delete("delete from ae where id = #{id} and week = #{week}")
    public boolean delete(AE domain);

    @Delete("delete from ae where id = #{id} and week>#{week}")
    public boolean deleteBigWeek(AE domain);

    @Select("select ae.id id, week, isAE, ae.name name, startDate, finishDate, degree, measure, relativity, result, isExit, patient_user.name idName from ae,patient_user where ae.id = patient_user.id and patient_user.doctorId = #{id} and (ae.name like #{search} or patient_user.name like #{search} or measure like #{search})")
    public List<AE> search(String search, String id);
}